package com.dw.etl.core.controller;

import javax.servlet.http.HttpServletRequest;

import com.dw.etl.common.base.BaseException;
import com.dw.etl.core.bean.vo.LayMsg;
import org.springframework.beans.factory.annotation.Autowired;
import  com.dw.etl.common.base.BaseResult;
import  com.dw.etl.common.constant.CommonResultConstant;
import com.dw.etl.core.api.MdMedTbService;
import com.dw.etl.core.bean.model.MdMedTb;
import org.springframework.util.StringUtils;
import  com.dw.etl.common.vo.PaginationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * mdMedTb控制器
 * Created by hozeData on 2021/06/17.
 */
@RestController
@RequestMapping("/etl/mdMedTb/")
@Api(description="开发中", tags="开发中")
@CrossOrigin(origins = "*", maxAge = 3600)
public class MdMedTbController {

    @Autowired
    MdMedTbService mdMedTbService;

    @ApiOperation(value="分页查询")
    @RequestMapping(value="findByPage", method=RequestMethod.GET)
    public LayMsg findByPage(String str, Integer page, Integer limit) {
        PaginationVO<MdMedTb> pageVO = mdMedTbService.findPageByModel(null, page, limit);
        return LayMsg.success().addCount(pageVO.getTotal()).addData(pageVO.getEntryList());
    }

    @ApiOperation(value="查询")
    @RequestMapping(value="find", method=RequestMethod.POST)
    public LayMsg find(@RequestBody MdMedTb mdMedTb) {
        List<MdMedTb> pageVO = mdMedTbService.findByModel(mdMedTb);
        return LayMsg.success().addData(pageVO);
    }

    @ApiOperation(value="保存")
    @ApiImplicitParam(name="mdMedPutfd", value="实体", paramType="body", required=true, dataType="MdMedPutfd")
    @RequestMapping(value="save", method=RequestMethod.POST)
    public BaseResult save(@RequestBody MdMedTb mdMedTb, HttpServletRequest request)  {
        int num;
        if(StringUtils.isEmpty(mdMedTb.getIdMedTb())) {
            num = mdMedTbService.insertSelective(mdMedTb);
        } else {
            num = mdMedTbService.updateByIdSelective(mdMedTb);
        }
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }

    @ApiOperation(value="详情")
    @ApiImplicitParam(name="idMedTb", value="主键", paramType="query", required=true, dataType="String")
    @RequestMapping(value="getById", method=RequestMethod.GET)
    public BaseResult getById(String idMedTb, HttpServletRequest request) throws BaseException {
        if(StringUtils.isEmpty(idMedTb)){
            throw new BaseException("请选择要编辑的项");
        }
        MdMedTb mdMedTb = mdMedTbService.getById(idMedTb);
        return new BaseResult(CommonResultConstant.SUCCESS, mdMedTb);
    }

    @ApiOperation(value="根据主键删除")
    @ApiImplicitParam(name="idMedTb", value="主键", paramType="query", required=true, dataType="String")
    @RequestMapping(value="delete", method=RequestMethod.GET)
    public BaseResult delete(String idMedTb, HttpServletRequest request) throws BaseException {
        if(StringUtils.isEmpty(idMedTb)){
            throw new BaseException("请选择要删除的项");
        }
        int num = mdMedTbService.deleteById(idMedTb);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }



}
